package com.example.fashionshoes.controller;

import com.example.fashionshoes.pojo.dto.GoodsPageDTO;
import com.example.fashionshoes.pojo.po.Category;
import com.example.fashionshoes.pojo.po.Result;
import com.example.fashionshoes.pojo.vo.CategoryGoodsVO;
import com.example.fashionshoes.pojo.vo.GoodsPageVO;
import com.example.fashionshoes.service.CategoryService;
import com.example.fashionshoes.service.GoodsService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    @Resource
    private GoodsService goodsService;
    /**
     * 获取所以分类
     * @return  分类数据
     */
    @GetMapping("/head")
    public Result<List<Category>> getCategory(){
        List<Category> list = categoryService.getCategory();
        return Result.success(list);
    }

    /**
     * 获取二级分类列表和商品
     * @param id 分类id
     * @return 分类列表和商品
     */
    @GetMapping
    public Result<CategoryGoodsVO> geTopCategory(@Param("id") Integer id){
        CategoryGoodsVO categoryGoodsVo = categoryService.getCategoryAndGoods(id);
        return Result.success(categoryGoodsVo);
    }

    /**
     * 获取二级分类
     * @param id 一级分类id
     * @return 二级分类
     */
    @GetMapping("/sub/filter")
    public Result<CategoryGoodsVO> getCategoryAndSubCategory(@Param("id") Integer id){
        CategoryGoodsVO categoryGoodsVo = categoryService.getCategoryAndSubCategory(id);
        return Result.success(categoryGoodsVo);
    }
    /**
     * 根据分类id分页获取对应商品
     * @param goodsPageDTO 分类id和分页数据
     * @return 分页对应商品
     */
    @PostMapping("/goods/temporary")
    public Result<GoodsPageVO> getSubGoods(@RequestBody GoodsPageDTO goodsPageDTO){
        GoodsPageVO goodsPageVO = goodsService.getSubGoods(goodsPageDTO);
        return Result.success(goodsPageVO);
    }

}
